#include <iostream>
#include <vector>
#include <climits>

using namespace std;
const int N = 1e5 + 10;
int p[N];

int main(){
	
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> p[i];
	int Max = INT_MIN;
	int prevMin =  INT_MAX;
	// 采用贪心算法
	for (int i = 1; i < n; i++){
		prevMin = std::min(prevMin, p[i - 1]);
		Max = std::max(p[i] - prevMin, Max);
	}
	cout << (Max < 0 ? 0 : Max) << endl;
	return 0;
}
